home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / lib / perl5 / Moose / Manual.pod < prev    next >
Encoding:
Text File  |  2010-07-02  |  7.5 KB  |  267 lines

  1. =pod
  2.  
  3. =head1 NAME
  4.  
  5. Moose::Manual - What is Moose, and how do I use it?
  6.  
  7. =head1 WHAT IS MOOSE?
  8.  
  9. Moose is a I<complete> object system for Perl 5. Consider any modern
  10. object-oriented language (which Perl 5 definitely isn't). It provides
  11. keywords for attribute declaration, object construction, inheritance,
  12. and maybe more. These keywords are part of the language, and you don't
  13. care how they are implemented.
  14.  
  15. Moose aims to do the same thing for Perl 5 OO. We can't actually
  16. create new keywords, but we do offer "sugar" that looks a lot like
  17. them. More importantly, with Moose, you I<define your class
  18. declaratively>, without needing to know about blessed hashrefs,
  19. accessor methods, and so on.
  20.  
  21. With Moose, you can concentrate on the I<logical> structure of your
  22. classes, focusing on "what" rather than "how". A class definition with
  23. Moose reads like a list of very concise English sentences.
  24.  
  25. Moose is built on top of C<Class::MOP>, a meta-object protocol (aka
  26. MOP). Using the MOP, Moose provides complete introspection for all
  27. Moose-using classes. This means you can ask classes about their
  28. attributes, parents, children, methods, etc., all using a well-defined
  29. API. The MOP abstracts away the symbol table, looking at C<@ISA> vars,
  30. and all the other crufty Perl tricks we know and love(?).
  31.  
  32. Moose is based in large part on the Perl 6 object system, as well as
  33. drawing on the best ideas from CLOS, Smalltalk, and many other
  34. languages.
  35.  
  36. =head1 WHY MOOSE?
  37.  
  38. Moose makes Perl 5 OO both simpler and more powerful. It encapsulates
  39. Perl 5 power tools in high-level declarative APIs which are easy to
  40. use. Best of all, you don't need to be a wizard to use it.
  41.  
  42. But if you want to dig about in the guts, Moose lets you do that too,
  43. by using and extending its powerful introspection API.
  44.  
  45. =head1 AN EXAMPLE
  46.  
  47.   package Person;
  48.  
  49.   use Moose;
  50.  
  51.   has 'first_name' => (
  52.       is  => 'rw',
  53.       isa => 'Str',
  54.   );
  55.  
  56.   has 'last_name' => (
  57.       is  => 'rw',
  58.       isa => 'Str',
  59.   );
  60.  
  61.   no Moose;
  62.   __PACKAGE__->meta->make_immutable;
  63.  
  64. This is a I<complete and usable> class definition!
  65.  
  66.   package User;
  67.  
  68.   use DateTime;
  69.   use Moose;
  70.  
  71.   extends 'Person';
  72.  
  73.   has 'password' => (
  74.       is  => 'rw',
  75.       isa => 'Str',
  76.   );
  77.  
  78.   has 'last_login' => (
  79.       is      => 'rw',
  80.       isa     => 'DateTime',
  81.       handles => { 'date_of_last_login' => 'date' },
  82.   );
  83.  
  84.   sub login {
  85.       my $self = shift;
  86.       my $pw   = shift;
  87.  
  88.       return 0 if $pw ne $self->password;
  89.  
  90.       $self->last_login( DateTime->now() );
  91.  
  92.       return 1;
  93.   }
  94.  
  95.   no Moose;
  96.   __PACKAGE__->meta->make_immutable;
  97.  
  98. We'll leave the line-by-line explanation of this code to other
  99. documentation, but you can see how Moose reduces common OO idioms to
  100. simple declarative constructs.
  101.  
  102. =head1 TABLE OF CONTENTS
  103.  
  104. This manual consists of a number of documents.
  105.  
  106. =over 4
  107.  
  108. =item L<Moose::Manual::Concepts>
  109.  
  110. Introduces Moose concepts, and contrasts them against "old school"
  111. Perl 5 OO.
  112.  
  113. =item L<Moose::Manual::Unsweetened>
  114.  
  115. Shows two example classes, each written first with Moose and then with
  116. "plain old Perl 5".
  117.  
  118. =item L<Moose::Manual::Classes>
  119.  
  120. How do you make use of Moose in your classes? Now that I'm a Moose,
  121. how do I subclass something?
  122.  
  123. =item L<Moose::Manual::Attributes>
  124.  
  125. Attributes are a core part of the Moose OO system. An attribute is a
  126. piece of data that an object has. Moose has a lot of attribute-related
  127. features!
  128.  
  129. =item L<Moose::Manual::Delegation>
  130.  
  131. Delegation is a powerful way to make use of attributes which are
  132. themselves objects.
  133.  
  134. =item L<Moose::Manual::Construction>
  135.  
  136. Learn how objects are built in Moose, and in particular about the
  137. C<BUILD> and C<BUILDARGS> methods. Also covers object destruction
  138. with C<DEMOLISH>.
  139.  
  140. =item L<Moose::Manual::MethodModifiers>
  141.  
  142. A method modifier lets you say "before calling method X, do this
  143. first", or "wrap method X in this code". Method modifiers are
  144. particularly handy in roles and with attribute accessors.
  145.  
  146. =item L<Moose::Manual::Roles>
  147.  
  148. A role is something a class does (like "Debuggable" or
  149. "Printable"). Roles provide a way of adding behavior to classes that
  150. is orthogonal to inheritance.
  151.  
  152. =item L<Moose::Manual::Types>
  153.  
  154. Moose's type system lets you strictly define what values an attribute
  155. can contain.
  156.  
  157. =item L<Moose::Manual::MOP>
  158.  
  159. Moose's meta API system lets you ask classes about their parents,
  160. children, methods, attributes, etc.
  161.  
  162. =item L<Moose::Manual::MooseX>
  163.  
  164. This document describes a few of the most useful Moose extensions on
  165. CPAN.
  166.  
  167. =item L<Moose::Manual::BestPractices>
  168.  
  169. Moose has a lot of features, and there's definitely more than one way
  170. to do it. However, we think that picking a subset of these features
  171. and using them consistently makes everyone's life easier.
  172.  
  173. =item L<Moose::Manual::FAQ>
  174.  
  175. Frequently asked questions about Moose.
  176.  
  177. =item L<Moose::Manual::Contributing>
  178.  
  179. Interested in hacking on Moose? Read this.
  180.  
  181. =item L<Moose::Manual::Delta>
  182.  
  183. This document details backwards-incompatibilities and other major
  184. changes to Moose.
  185.  
  186. =back
  187.  
  188. =head1 JUSTIFICATION
  189.  
  190. If you're still asking yourself "Why do I need this?", then this
  191. section is for you.
  192.  
  193. =over 4
  194.  
  195. =item Another object system!?!?
  196.  
  197. Yes, we know there are many, many ways to build objects in Perl 5,
  198. many of them based on inside-out objects and other such things. Moose
  199. is different because it is not a new object system for Perl 5, but
  200. instead an extension of the existing object system.
  201.  
  202. Moose is built on top of L<Class::MOP>, which is a metaclass system
  203. for Perl 5. This means that Moose not only makes building normal
  204. Perl 5 objects better, but it also provides the power of metaclass
  205. programming.
  206.  
  207. =item Is this for real? Or is this just an experiment?
  208.  
  209. Moose is I<based> on the prototypes and experiments Stevan did for the
  210. Perl 6 meta-model. However, Moose is B<NOT> an experiment or
  211. prototype; it is for B<real>.
  212.  
  213. =item Is this ready for use in production?
  214.  
  215. Yes.
  216.  
  217. Moose has been used successfully in production environments by many
  218. people and companies. There are Moose applications which have been in
  219. production with little or no issue now for years. We consider it
  220. highly stable and we are committed to keeping it stable.
  221.  
  222. Of course, in the end, you need to make this call yourself. If you
  223. have any questions or concerns, please feel free to email Stevan or
  224. the moose@perl.org list, or just stop by irc.perl.org#moose and ask
  225. away.
  226.  
  227. =item Is Moose just Perl 6 in Perl 5?
  228.  
  229. No. While Moose is very much inspired by Perl 6, it is not itself Perl
  230. 6. Instead, it is an OO system for Perl 5. Stevan built Moose because
  231. he was tired of writing the same old boring Perl 5 OO code, and
  232. drooling over Perl 6 OO. So instead of switching to Ruby, he wrote
  233. Moose :)
  234.  
  235. =item Wait, I<post> modern, I thought it was just I<modern>?
  236.  
  237. Stevan read Larry Wall's talk from the 1999 Linux World entitled
  238. "Perl, the first postmodern computer language" in which he talks about
  239. how he picked the features for Perl because he thought they were cool
  240. and he threw out the ones that he thought sucked. This got him
  241. thinking about how we have done the same thing in Moose. For Moose, we
  242. have "borrowed" features from Perl 6, CLOS (LISP), Smalltalk, Java,
  243. BETA, OCaml, Ruby and more, and the bits we didn't like (cause they
  244. sucked) we tossed aside. So for this reason (and a few others) Stevan
  245. has re-dubbed Moose a I<postmodern> object system.
  246.  
  247. Nuff Said.
  248.  
  249. =back
  250.  
  251. =head1 AUTHORS
  252.  
  253. Dave Rolsky E<lt>autarch@urth.orgE<gt>
  254.  
  255. Stevan Little E<lt>stevan@iinteractive.comE<gt>
  256.  
  257. =head1 COPYRIGHT AND LICENSE
  258.  
  259. Copyright 2008-2009 by Infinity Interactive, Inc.
  260.  
  261. L<http://www.iinteractive.com>
  262.  
  263. This library is free software; you can redistribute it and/or modify
  264. it under the same terms as Perl itself.
  265.  
  266. =cut
  267.